﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Entities.Users;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Text.RegularExpressions;
    using System.Web.UI.WebControls;

    public class AdminClients : BaseAdminModule
    {
        [AccessedThroughProperty("Clients1")]
        private Clients _Clients1;
        [AccessedThroughProperty("cmdCreateOrder")]
        private LinkButton _cmdCreateOrder;
        [AccessedThroughProperty("cmdResetPass")]
        private LinkButton _cmdResetPass;
        [AccessedThroughProperty("cmdReturn2")]
        private LinkButton _cmdReturn2;
        [AccessedThroughProperty("cmdUnlock")]
        private LinkButton _cmdUnlock;
        [AccessedThroughProperty("cmdUpdate")]
        private LinkButton _cmdUpdate;
        [AccessedThroughProperty("cmdViewOrders")]
        private LinkButton _cmdViewOrders;
        [AccessedThroughProperty("lblDisplayName")]
        private Label _lblDisplayName;
        [AccessedThroughProperty("lblEmail")]
        private Label _lblEmail;
        [AccessedThroughProperty("lblFirstName")]
        private Label _lblFirstName;
        [AccessedThroughProperty("lblLastName")]
        private Label _lblLastName;
        [AccessedThroughProperty("lblUserID")]
        private Label _lblUserID;
        [AccessedThroughProperty("lblUserName")]
        private Label _lblUserName;
        [AccessedThroughProperty("lblViewDisplayName")]
        private Label _lblViewDisplayName;
        [AccessedThroughProperty("lblViewFirstName")]
        private Label _lblViewFirstName;
        [AccessedThroughProperty("lblViewLastName")]
        private Label _lblViewLastName;
        [AccessedThroughProperty("lblViewUserID")]
        private Label _lblViewUserID;
        [AccessedThroughProperty("lblViewUserName")]
        private Label _lblViewUserName;
        [AccessedThroughProperty("pnlEdit")]
        private Panel _pnlEdit;
        [AccessedThroughProperty("pnlList")]
        private Panel _pnlList;
        [AccessedThroughProperty("txtEmail")]
        private TextBox _txtEmail;
        private int _UsrID;

        public AdminClients()
        {
            base.Load += new EventHandler(this.Page_Load);
        }

        private void Clients1_SelectedUser(int UserID)
        {
            this.Response.Redirect(this.EditUrl("uid", UserID.ToString(), "AdminClients"));
        }

        private void cmdCreateOrder_Click(object sender, EventArgs e)
        {
            OrderController controller = new OrderController();
            if (Versioned.IsNumeric(this.Request.QueryString["uid"]))
            {
                NB_Store_OrdersInfo info = controller.CreateEmptyOrder(Conversions.ToString(this.PortalId), Conversions.ToInteger(this.Request.QueryString["uid"]));
                this.Response.Redirect(this.EditUrl("OrdId", info.OrderID.ToString(), "AdminOrders", new string[] { "uid=" + this.Request.QueryString["uid"], "ed=1" }));
            }
        }

        private void cmdResetPass_Click(object sender, EventArgs e)
        {
            try
            {
                new ClientController().ResetPassword(this.PortalId, Conversions.ToInteger(this.lblViewUserID.Text));
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdReturn2_Click(object sender, EventArgs e)
        {
            this.Response.Redirect(this.EditUrl("AdminClients"));
        }

        private void cmdUnlock_Click(object sender, EventArgs e)
        {
            try
            {
                new ClientController().UnlockUser(this.PortalId, Conversions.ToInteger(this.lblViewUserID.Text));
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                ClientController controller = new ClientController();
                if (Regex.IsMatch(this.txtEmail.Text, "[^\"\\r\\n]*\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))
                {
                    controller.updateEmail(this.PortalId, Conversions.ToInteger(this.lblViewUserID.Text), this.txtEmail.Text);
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        private void cmdViewOrders_Click(object sender, EventArgs e)
        {
            this.Response.Redirect(this.EditUrl("uid", this.Request.QueryString["uid"], "AdminOrders", new string[] { "rtnctl=AdminClients" }));
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                if (this.Request.QueryString["uid"] != null)
                {
                    if (Versioned.IsNumeric(this.Request.QueryString["uid"]))
                    {
                        this._UsrID = Conversions.ToInteger(this.Request.QueryString["uid"]);
                        this.pnlList.Visible = false;
                        this.pnlEdit.Visible = true;
                        this.populateEdit();
                    }
                }
                else
                {
                    this.pnlList.Visible = true;
                    this.pnlEdit.Visible = false;
                }
            }
            this.Clients1.PortalID = Conversions.ToString(this.PortalId);
            this.Clients1.ResourceFile = this.LocalResourceFile;
        }

        private void populateEdit()
        {
            try
            {
                UserInfo info = UserController.GetUser(this.PortalId, this._UsrID, false);
                if (info == null)
                {
                    this.pnlEdit.Visible = false;
                }
                else if (info.IsInRole("Administrators") | info.IsSuperUser)
                {
                    this.pnlEdit.Visible = false;
                }
                else
                {
                    this.cmdResetPass.Attributes.Add("onClick", "javascript:return confirm('" + DotNetNuke.Services.Localization.Localization.GetString("cmdResetPassMsg", this.LocalResourceFile) + "');");
                    this.cmdUnlock.Attributes.Add("onClick", "javascript:return confirm('" + DotNetNuke.Services.Localization.Localization.GetString("cmdUnlockMsg", this.LocalResourceFile) + "');");
                    this.lblViewDisplayName.Text = info.DisplayName;
                    this.lblViewFirstName.Text = info.FirstName;
                    this.lblViewLastName.Text = info.LastName;
                    this.lblViewUserID.Text = Conversions.ToString(this._UsrID);
                    this.lblViewUserName.Text = info.Username;
                    this.txtEmail.Text = info.Email;
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                ProjectData.ClearProjectError();
            }
        }

        protected virtual Clients Clients1
        {
            get
            {
                return this._Clients1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                Clients.SelectedUserEventHandler handler = new Clients.SelectedUserEventHandler(this.Clients1_SelectedUser);
                if (this._Clients1 != null)
                {
                    this._Clients1.SelectedUser -= handler;
                }
                this._Clients1 = value;
                if (this._Clients1 != null)
                {
                    this._Clients1.SelectedUser += handler;
                }
            }
        }

        protected virtual LinkButton cmdCreateOrder
        {
            get
            {
                return this._cmdCreateOrder;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdCreateOrder_Click);
                if (this._cmdCreateOrder != null)
                {
                    this._cmdCreateOrder.Click -= handler;
                }
                this._cmdCreateOrder = value;
                if (this._cmdCreateOrder != null)
                {
                    this._cmdCreateOrder.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdResetPass
        {
            get
            {
                return this._cmdResetPass;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdResetPass_Click);
                if (this._cmdResetPass != null)
                {
                    this._cmdResetPass.Click -= handler;
                }
                this._cmdResetPass = value;
                if (this._cmdResetPass != null)
                {
                    this._cmdResetPass.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdReturn2
        {
            get
            {
                return this._cmdReturn2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdReturn2_Click);
                if (this._cmdReturn2 != null)
                {
                    this._cmdReturn2.Click -= handler;
                }
                this._cmdReturn2 = value;
                if (this._cmdReturn2 != null)
                {
                    this._cmdReturn2.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdUnlock
        {
            get
            {
                return this._cmdUnlock;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdUnlock_Click);
                if (this._cmdUnlock != null)
                {
                    this._cmdUnlock.Click -= handler;
                }
                this._cmdUnlock = value;
                if (this._cmdUnlock != null)
                {
                    this._cmdUnlock.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdUpdate
        {
            get
            {
                return this._cmdUpdate;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdUpdate_Click);
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click -= handler;
                }
                this._cmdUpdate = value;
                if (this._cmdUpdate != null)
                {
                    this._cmdUpdate.Click += handler;
                }
            }
        }

        protected virtual LinkButton cmdViewOrders
        {
            get
            {
                return this._cmdViewOrders;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                EventHandler handler = new EventHandler(this.cmdViewOrders_Click);
                if (this._cmdViewOrders != null)
                {
                    this._cmdViewOrders.Click -= handler;
                }
                this._cmdViewOrders = value;
                if (this._cmdViewOrders != null)
                {
                    this._cmdViewOrders.Click += handler;
                }
            }
        }

        protected virtual Label lblDisplayName
        {
            get
            {
                return this._lblDisplayName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblDisplayName = value;
            }
        }

        protected virtual Label lblEmail
        {
            get
            {
                return this._lblEmail;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblEmail = value;
            }
        }

        protected virtual Label lblFirstName
        {
            get
            {
                return this._lblFirstName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblFirstName = value;
            }
        }

        protected virtual Label lblLastName
        {
            get
            {
                return this._lblLastName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblLastName = value;
            }
        }

        protected virtual Label lblUserID
        {
            get
            {
                return this._lblUserID;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblUserID = value;
            }
        }

        protected virtual Label lblUserName
        {
            get
            {
                return this._lblUserName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblUserName = value;
            }
        }

        protected virtual Label lblViewDisplayName
        {
            get
            {
                return this._lblViewDisplayName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblViewDisplayName = value;
            }
        }

        protected virtual Label lblViewFirstName
        {
            get
            {
                return this._lblViewFirstName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblViewFirstName = value;
            }
        }

        protected virtual Label lblViewLastName
        {
            get
            {
                return this._lblViewLastName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblViewLastName = value;
            }
        }

        protected virtual Label lblViewUserID
        {
            get
            {
                return this._lblViewUserID;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblViewUserID = value;
            }
        }

        protected virtual Label lblViewUserName
        {
            get
            {
                return this._lblViewUserName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblViewUserName = value;
            }
        }

        protected virtual Panel pnlEdit
        {
            get
            {
                return this._pnlEdit;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._pnlEdit = value;
            }
        }

        protected virtual Panel pnlList
        {
            get
            {
                return this._pnlList;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._pnlList = value;
            }
        }

        protected virtual TextBox txtEmail
        {
            get
            {
                return this._txtEmail;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._txtEmail = value;
            }
        }
    }
}

